package com.esri.core.tasks.geocode;

import com.esri.core.geometry.Point;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.io.handler.h;
import com.esri.core.internal.io.handler.n;
import com.esri.core.internal.tasks.a.a;
import com.esri.core.internal.tasks.a.b;
import com.esri.core.internal.tasks.a.c;
import com.esri.core.internal.tasks.a.e;
import com.esri.core.internal.tasks.a.f;
import com.esri.core.internal.tasks.a.g;
import com.esri.core.io.UserCredentials;
import java.util.List;
import java.util.Map;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public class OnlineLocator extends Locator {
    private static final String ESRI_WORLD_LOCATOR_URL = "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer";
    private UserCredentials credential;
    private String url;

    public OnlineLocator() {
        this.credential = null;
        this.url = ESRI_WORLD_LOCATOR_URL;
    }

    public OnlineLocator(String str) {
        this.credential = null;
        this.url = str;
    }

    public OnlineLocator(String str, UserCredentials userCredentials) {
        this.credential = null;
        this.url = str;
        this.credential = userCredentials != null ? userCredentials.getCopy() : null;
    }

    @Override // com.esri.core.tasks.geocode.Locator
    public String getUrl() {
        return this.url;
    }

    @Override // com.esri.core.tasks.geocode.Locator
    public LocatorServiceInfo getInfo() throws Exception {
        String str = this.url;
        return LocatorServiceInfo.fromJson(h.a(str, (Map<String, String>) null, n.a(str, this.credential)));
    }

    @Override // com.esri.core.tasks.geocode.Locator
    public List<LocatorGeocodeResult> geocode(Map<String, String> map, List<String> list) throws Exception {
        return geocode(map, list, (SpatialReference) null);
    }

    @Override // com.esri.core.tasks.geocode.Locator
    public List<LocatorGeocodeResult> geocode(Map<String, String> map, List<String> list, SpatialReference spatialReference) throws Exception {
        return geocode(createGeocodeParams(map, list, spatialReference));
    }

    @Override // com.esri.core.tasks.geocode.Locator
    public List<LocatorGeocodeResult> geocode(LocatorGeocodeParameters locatorGeocodeParameters) throws Exception {
        return new e(locatorGeocodeParameters.internalParams, this.url, this.credential).execute();
    }

    @Override // com.esri.core.tasks.geocode.Locator
    public List<LocatorGeocodeResult> find(LocatorFindParameters locatorFindParameters) throws Exception {
        return new c(locatorFindParameters.getParams(), getUrl(), this.credential).execute();
    }

    @Override // com.esri.core.tasks.geocode.Locator
    public LocatorReverseGeocodeResult reverseGeocode(Point point, double d) throws Exception {
        return reverseGeocode(point, d, null, null);
    }

    @Override // com.esri.core.tasks.geocode.Locator
    public LocatorReverseGeocodeResult reverseGeocode(Point point, double d, SpatialReference spatialReference, SpatialReference spatialReference2) throws Exception {
        return new g(generateReverseGeocodeParams(point, d, spatialReference, spatialReference2), this.url, this.credential).execute();
    }

    @Override // com.esri.core.tasks.geocode.Locator
    public BatchGeocodeResult batchGeocode(List<Map<String, String>> list, SpatialReference spatialReference) throws Exception {
        return new b(createBatchGeocodeParams(list, spatialReference), this.url, this.credential).execute();
    }

    @Override // com.esri.core.tasks.geocode.Locator
    public List<LocatorGeocodeResult> find(LocatorSuggestionResult locatorSuggestionResult, int i, List<String> list, SpatialReference spatialReference) throws Exception {
        LocatorFindParameters locatorFindParameters = new LocatorFindParameters(locatorSuggestionResult.getText());
        locatorFindParameters.setMagicKey(locatorSuggestionResult.getMagicKey());
        locatorFindParameters.setOutFields(list);
        locatorFindParameters.setMaxLocations(i);
        locatorFindParameters.setOutSR(spatialReference);
        return new c(locatorFindParameters.getParams(), this.url, this.credential).execute();
    }

    @Override // com.esri.core.tasks.geocode.Locator
    public List<LocatorSuggestionResult> suggest(LocatorSuggestionParameters locatorSuggestionParameters) throws Exception {
        return new com.esri.core.internal.tasks.a.h(locatorSuggestionParameters.getInternalParameters(), this.url, this.credential).execute();
    }

    private f generateReverseGeocodeParams(Point point, double d, SpatialReference spatialReference, SpatialReference spatialReference2) {
        f fVar = new f();
        fVar.a = point;
        fVar.b = d;
        fVar.c = spatialReference;
        fVar.d = spatialReference2;
        return fVar;
    }

    private LocatorGeocodeParameters createGeocodeParams(Map<String, String> map, List<String> list, SpatialReference spatialReference) {
        LocatorGeocodeParameters locatorGeocodeParameters = new LocatorGeocodeParameters();
        locatorGeocodeParameters.setAddressFields(map);
        locatorGeocodeParameters.setOutFields(list);
        locatorGeocodeParameters.setOutSR(spatialReference);
        return locatorGeocodeParameters;
    }

    private a createBatchGeocodeParams(List<Map<String, String>> list, SpatialReference spatialReference) {
        a aVar = new a();
        aVar.a = list;
        aVar.b = spatialReference;
        return aVar;
    }
}
